package com.lollipop.rabbitmq.seven;

import com.lollipop.rabbitmq.util.RabbitMqUtiils;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeoutException;

/**
 * @Author: Lollipop
 * @Date: 2021-10-05 20:16
 * @Description:
 */
public class EmitLogTopic {
    public static final String EXCHANGE_NAME = "topic_logs";

    public static void main(String[] args) throws IOException, TimeoutException {
        Channel channel = RabbitMqUtiils.getChannel();
        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.TOPIC);
        Map<String, String> bindingKeyMap = new HashMap<>();
        bindingKeyMap.put("lazy.orange.a", "Q1、Q2接收");
        bindingKeyMap.put("fast.orange.b", "Q1接收");
        bindingKeyMap.put("lazy.blue.a", "Q2接收");
        bindingKeyMap.put("a.blue.c", "不匹配key，不会被接收");
        for (Map.Entry<String, String> it : bindingKeyMap.entrySet()) {
            String routingKey = it.getKey();
            String message = it.getValue();
            channel.basicPublish(EXCHANGE_NAME, routingKey, null, message.getBytes(StandardCharsets.UTF_8));
            System.out.println("发出消息：" + message);
        }
    }
}
